/*

This file sets up tables

*/


*** Calculate depreciation rate

use "/projects/data/dataSTATA/combined/combined_iv_energy.dta", clear
* Define scalars used in the script in a secondary script for disclosure purposes (same scalar as 5_combine_model)
do programs/codeSTATA/A_cleaning/5_combine_model_scalars.do

* identify firms that are always surveyed
destring lbdnum, replace
xtset lbdnum year
tsfill

keep if year > 2001 & year < 2008
bys lbdnum: egen count_n = count(firstyear)
keep if count_n == 6
keep year lbdnum ks ck
reshape wide ks ck, i(lbdnum) j(year)
drop if ks2002 == 0
gen n = _n
gen ck2006_ks2007 = ck2006 - ks2007
gen d = .


sum n
* loop over each obs
forvalues i = 1(1)ndepreciation {
preserve

		keep if n == `i'
		sum n
	
		mata: mata clear
		* mata

		mata M = st_data(., .)

		* make sure to preserve order!!
		mata d = polyroots((M[1,15],M[1,11],M[1,9],M[1,7],M[1,5],M[1,2]))

		* mata dReal = select(d,Im(d):==0)
		
		mata dReal = d[1,5]

		mata dReal = Re(dReal)
		
		* mata dReal = dReal[1,1]

		mata st_store(1,16,dReal)

		* end
	keep lbdnum d
	ren d dep
	if `i' > 1 append using `dep'
	tempfile dep
	sa `dep', replace
	
restore

}

merge 1:1 lbdnum using `dep', assert(1 3) keep(1 3) nogen
replace d =  1 - dep
drop dep

sum d 
gen mean = `r(mean)'
gen Obs = `r(N)'

** Round observation count - code taken from rounding_N.do:
foreach var in "Obs" {
if "`var'"=="" exit

replace `var' = round(`var', 10) if `var'>=15&`var'<=99 
replace `var' = round(`var', 50) if `var'>=100&`var'<=999 
replace `var' = round(`var', 100) if `var'>=1000&`var'<=9999 
replace `var' = round(`var', 500) if `var'>=10000&`var'<=99999 
replace `var' = round(`var', 1000) if `var'>=100000&`var'<=999999 
replace `var' = round(`var',10^(floor(log10(`var'))-3)) if `var'>=1000000 

if `var'<15 capture gen `var'_less15=0
capture replace `var'_less15=1 if `var'<15
capture replace `var'_less15=0 if `var'>=15
replace `var'=. if `var'<15
}

** Round mean - code taken from rounding_4sigdig_v2.do:
foreach var in "mean"{
if "`var'"=="" exit

replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0

}

keep mean Obs
duplicates drop 

mkmat mean Obs, mat(m)

esttab matrix(m) using "/projects/disclosure/20240417/output/depreciation_T13T26.xls", title(Depreciation rate) replace

**************** Now add requested regressions **************** 

use "/projects/data/dataSTATA/combined/combined_productivity_energy_4digit_4m.dta", clear

* drop obs that would be excluded from regressions --> generate constant sample
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

reghdfe lelec_price_init instr_B_cl instr_B_ng instr_B_pa instr_B_cl_init instr_B_ng_init instr_B_pa_init   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

gen age = year - firstyear

*>--------- define rounding function for regs---------------------<
* copied from rounding_regs.do Census file provided

capture program drop round
program define round, eclass
   mat A = e(b)
   forval j = 1/`=colsof(matrix(A))' { 
      mat A[1,`j'] = round(A[1,`j'],10^(floor(log10(abs(A[1,`j'])))-3))
   } 
   ereturn repost b = A

   if e(N)>=15&e(N)<=99 ereturn scalar N = round(e(N), 10)
   if e(N)>=100&e(N)<=999 ereturn scalar N = round(e(N), 50)
   if e(N)>=1000&e(N)<=9999 ereturn scalar N = round(e(N), 100)
   if e(N)>=10000&e(N)<=99999 ereturn scalar N = round(e(N), 500)
   if e(N)>=100000&e(N)<=999999 ereturn scalar N = round(e(N), 1000)
   if e(N)>=1000000 ereturn scalar N = round(e(N),10^(floor(log10(e(N)))-3))

   if e(N)<15 {
   scalar N_less15=1
   ereturn scalar N=.
   }

   if e(df_r)>=15&e(df_r)<=99 ereturn scalar df_r = round(e(df_r), 10)
   if e(df_r)>=100&e(df_r)<=999 ereturn scalar df_r = round(e(df_r), 50)
   if e(df_r)>=1000&e(df_r)<=9999 ereturn scalar df_r = round(e(df_r), 100)
   if e(df_r)>=10000&e(df_r)<=99999 ereturn scalar df_r = round(e(df_r), 500)
   if e(df_r)>=100000&e(df_r)<=999999 ereturn scalar df_r = round(e(df_r), 1000)
   if e(df_r)>=1000000 ereturn scalar df_r = round(e(df_r),10^(floor(log10(e(df_r)))-3))

   if e(df_r)<15 {
   scalar df_less15=1
   ereturn scalar df_r=.
   }

   capture ereturn scalar r2 = round(e(r2),10^(floor(log10(e(r2)))-3))
   capture ereturn scalar r2_a = round(e(r2_a),10^(floor(log10(e(r2_a)))-3))
   capture ereturn scalar F = round(e(F),10^(floor(log10(e(F)))-3))
   capture ereturn scalar rmse = round(e(rmse),10^(floor(log10(e(rmse)))-3))
   capture ereturn scalar mss = round(e(mss),10^(floor(log10(e(mss)))-3))
   capture ereturn scalar rss = round(e(rss),10^(floor(log10(e(rss)))-3))
   capture ereturn scalar rkf = round(e(rkf),10^(floor(log10(e(rkf)))-3))

end

********** Add regression to table A.6 that includes log(1+tvs) as an outcome **********
* revenue
drop ltvs
gen ltvs = log(1+tvs)
ivreghdfe ltvs  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

esttab using "/projects/disclosure/20240417/output/revenue_outcome_T13T26.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init ) mtitles("Revenue") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear 


********** Add panel to table A.8 that controls for log(capital), log(materials), and log(labor) ********** 
* controlling for labor, capital, and materials 
drop lcl lcm liks_i
gen lcl = log(cl)
gen lcm = log(cm)
gen liks_i = log(iks_i)

ivreghdfe we_scale lcl lcm liks_i (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe we_scale lcl lcm liks_i (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
ivreghdfe wh lcl lcm liks_i (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe wh lcl lcm liks_i (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

esttab using "/projects/disclosure/20240417/output/robustness_productivity_labor_capital_materials_T13T26.xls", b(3) se(3) obslast append star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries") title("controlling for labor, capital, and materials") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear


********** Add panel to table A.7 that controls for log(capital), log(materials), and log(labor) ********** 

* controlling for labor, capital, and materials 
ivreghdfe lelec_int lcl lcm liks_i (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lelec_int lcl lcm liks_i (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
ivreghdfe lco2_int_i_both lcl lcm liks_i (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lbtu_int_i_both lcl lcm liks_i (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

esttab using "/projects/disclosure/20240417/output/robustness_energy_intensity_labor_capital_materials_T13T26.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity") title("controlling for labor, capital, and materials") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear



*----------------------------- Generate dataset for lagged prices -----------------------------*

** create year x state x industry price averages
preserve

collapse (mean) lelec_price, by(year fipsst bestnaics instr_B_cl instr_B_ng instr_B_pa )
rename lelec_price lelec_price_y_s_n

tempfile price_y_s_n
save `price_y_s_n', replace

restore

** create list of unique fips state code 
preserve 

keep fipsst
duplicates drop

tempfile states
save `states', replace

restore

** create year x industry price average for those states that have no firms in that industry x year
preserve

collapse (mean) lelec_price, by(year bestnaics)
rename lelec_price lelec_price_y_n

cross using `states'

merge 1:1 year bestnaics fipsst using `price_y_s_n', nogen

replace lelec_price_y_s_n = lelec_price_y_n if lelec_price_y_s_n==.
drop lelec_price_y_n
gen bestnaics_neg = bestnaics*-1

foreach var in instr_B_cl instr_B_ng instr_B_pa {
	by year fipsst (bestnaics), sort: replace `var' = `var'[_n-1] if `var' >= .
	by year fipsst (bestnaics_neg), sort: replace `var' = `var'[_n-1] if `var' >= .
}

drop bestnaics_neg
rename (year instr_B_cl instr_B_ng instr_B_pa) (year_mean instr_B_cl_y_s instr_B_ng_y_s instr_B_pa_y_s)

tempfile price_y_s_n2
save `price_y_s_n2', replace

restore

** now merge back on to original dataset 

preserve

keep year firstyear bestnaics firmid lbdnum fipsst

joinby bestnaics fipsst using `price_y_s_n2'

drop if year_mean<=firstyear | year_mean>=year | year==firstyear+1

foreach var in instr_B_cl_y_s instr_B_ng_y_s instr_B_pa_y_s lelec_price_y_s_n {
	gen `var'_1l = . 
	replace `var'_1l = `var' if year_mean == year-1
}
collapse (mean) *_y_*, by(year firstyear bestnaics firmid lbdnum fipsst)

rename (instr_B_cl_y_s_1l instr_B_ng_y_s_1l instr_B_pa_y_s_1l lelec_price_y_s_n_1l) (instr_B_cl_1lag instr_B_ng_1lag instr_B_pa_1lag lelec_price_1lag)

tempfile inter_year_means
save `inter_year_means', replace

restore

preserve

drop if year==firstyear | year==firstyear+1

merge 1:1 year firstyear bestnaics firmid lbdnum fipsst using `inter_year_means'


********** Add panel to table A.8 that controls for mean of inter-year prices ********** 
ivreghdfe we_scale (lelec_price lelec_price_init lelec_price_y_s_n = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_y_s instr_B_ng_y_s instr_B_pa_y_s) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe we_scale (lelec_price lelec_price_init lelec_price_y_s_n = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_y_s instr_B_ng_y_s instr_B_pa_y_s) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
ivreghdfe wh (lelec_price lelec_price_init lelec_price_y_s_n = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_y_s instr_B_ng_y_s instr_B_pa_y_s) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe wh (lelec_price lelec_price_init lelec_price_y_s_n = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_y_s instr_B_ng_y_s instr_B_pa_y_s) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

esttab using "/projects/disclosure/20240417/output/robustness_productivity_interyear_price_means_T13T26.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init lelec_price_y_s_n) mtitles("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries") title("controlling for the mean of inter-year prices") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price) lelec_price_y_s_n Mean(log(Inter_Year_Electricity_Price))) scalars("rkf K-P F stat") sfmt(1)
eststo clear


********** Add panel to table A.7 that controls for mean of inter-year prices ********** 
ivreghdfe lelec_int (lelec_price lelec_price_init lelec_price_y_s_n = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_y_s instr_B_ng_y_s instr_B_pa_y_s) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lelec_int (lelec_price lelec_price_init lelec_price_y_s_n = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_y_s instr_B_ng_y_s instr_B_pa_y_s) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
ivreghdfe lco2_int_i_both (lelec_price lelec_price_init lelec_price_y_s_n = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_y_s instr_B_ng_y_s instr_B_pa_y_s) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lbtu_int_i_both (lelec_price lelec_price_init lelec_price_y_s_n = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_y_s instr_B_ng_y_s instr_B_pa_y_s) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

esttab using "/projects/disclosure/20240417/output/robustness_energy_intensity_interyear_price_means_T13T26.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init lelec_price_y_s_n) mtitles("Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity") title("controlling for the mean of inter-year prices") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price) lelec_price_y_s_n Mean(log(Inter_Year_Electricity_Price))) scalars("rkf K-P F stat") sfmt(1)
eststo clear


********** Add panels to A.8 that control for 1 year lagged prices (one for logs, one for levels) ********** 
** Logs
ivreghdfe we_scale (lelec_price lelec_price_init lelec_price_1lag = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_1lag instr_B_cl_1lag instr_B_cl_1lag) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe we_scale (lelec_price lelec_price_init lelec_price_1lag = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_1lag instr_B_cl_1lag instr_B_cl_1lag) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
ivreghdfe wh (lelec_price lelec_price_init lelec_price_1lag = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_1lag instr_B_cl_1lag instr_B_cl_1lag) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe wh (lelec_price lelec_price_init lelec_price_1lag = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_1lag instr_B_cl_1lag instr_B_cl_1lag) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

esttab using "/projects/disclosure/20240417/output/robustness_productivity_1year_lag_T13T26.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries") title("controlling for the 1 year lagged prices") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price) lelec_price_1lag log(1Year_Lagged_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear

** Levels
gen we_scale_lev = exp(we_scale)
gen wh_lev = exp(wh)

ivreghdfe we_scale_lev (lelec_price lelec_price_init lelec_price_1lag = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_1lag instr_B_cl_1lag instr_B_cl_1lag) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
local coef1 = round(r(table)[1,1],.001)
local se1 = round(r(table)[2,1],.001)
local coef2 = round(r(table)[1,2],.001)
local se2 = round(r(table)[2,2],.001)
local coef3 = round(r(table)[1,3],.001)
local se3 = round(r(table)[2,3],.001)
local fstat = round(e(widstat),.1)
local N = round(e(N),10^(floor(log10(e(N)))-3))
mat m = (`coef1' \ `se1' \  `coef2' \ `se2' \ `coef3' \ `se3' \ `fstat' \ `N')

ivreghdfe we_scale_lev (lelec_price lelec_price_init lelec_price_1lag = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_1lag instr_B_cl_1lag instr_B_cl_1lag) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
local coef1 = round(r(table)[1,1],.001)
local se1 = round(r(table)[2,1],.001)
local coef2 = round(r(table)[1,2],.001)
local se2 = round(r(table)[2,2],.001)
local coef3 = round(r(table)[1,3],.001)
local se3 = round(r(table)[2,3],.001)
local fstat = round(e(widstat),.1)
local N = round(e(N),1000)
mat m1 = (`coef1' \ `se1' \  `coef2' \ `se2' \ `coef3' \ `se3' \ `fstat' \ `N')
mat m = (m, m1)

ivreghdfe wh_lev (lelec_price lelec_price_init lelec_price_1lag = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_1lag instr_B_cl_1lag instr_B_cl_1lag) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
local coef1 = round(r(table)[1,1],.1)
local se1 = round(r(table)[2,1],.1)
local coef2 = round(r(table)[1,2],.1)
local se2 = round(r(table)[2,2],.1)
local coef3 = round(r(table)[1,3],.1)
local se3 = round(r(table)[2,3],.1)
local fstat = round(e(widstat),.1)
local N = round(e(N),10^(floor(log10(e(N)))-3))
mat m1 = (`coef1' \ `se1' \  `coef2' \ `se2' \ `coef3' \ `se3' \ `fstat' \ `N')
mat m = (m, m1)

ivreghdfe wh_lev (lelec_price lelec_price_init lelec_price_1lag = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_1lag instr_B_cl_1lag instr_B_cl_1lag) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
local coef1 = round(r(table)[1,1],.1)
local se1 = round(r(table)[2,1],.1)
local coef2 = round(r(table)[1,2],.1)
local se2 = round(r(table)[2,2],.1)
local coef3 = round(r(table)[1,3],.1)
local se3 = round(r(table)[2,3],.1)
local fstat = round(e(widstat),.1)
local N = round(e(N),1000)
mat m1 = (`coef1' \ `se1' \  `coef2' \ `se2' \ `coef3' \ `se3' \ `fstat' \ `N')
mat m = (m, m1)

mat rownames m = log(Current_Electricity_Price) se log(Initial_Electricity_Price) se log(1Year_Lagged_Electricity_Price) se "K-P F stat" N
mat colnames m = "Energy Productivity" "Energy Prod Elec Int Industries" "Total Factor Productivity" "TFP Elec Int Industries"

esttab matrix(m) using "/projects/disclosure/20240417/output/robustness_productivity_levels_1year_lag_T13T26.xls", title("controlling for the 1 year lagged prices") replace
eststo clear 

restore 


********** Add panels to table A.8 once for firms 5 years and younger, once for firms 10 years and older ********** 
gen young_firm = 0
replace young_firm = 1 if year <= firstyear+5

gen old_firm = 0
replace old_firm = 1 if year >= firstyear+10

** young firms
ivreghdfe we_scale (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if young_firm==1
eststo: round
ivreghdfe we_scale (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7 & young_firm==1
eststo: round
ivreghdfe wh (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if young_firm==1
eststo: round
ivreghdfe wh (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7 & young_firm==1
eststo: round

esttab using "/projects/disclosure/20240417/output/robustness_productivity_young_firms_T13T26.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries") title("for young firms only") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear


** old firms
ivreghdfe we_scale (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if old_firm==1
eststo: round
ivreghdfe we_scale (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7 & old_firm==1
eststo: round
ivreghdfe wh (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if old_firm==1
eststo: round
ivreghdfe wh (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7 & old_firm==1
eststo: round

esttab using "/projects/disclosure/20240417/output/robustness_productivity_old_firms_T13T26.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Energy Productivity" "Energy Productivity, Elec. Intensive Industries" "Total Factor Productivity" "Total Factor Productivity, Elec. Intensive Industries") title("for old firms only") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear



********** Add panels to table A.7  once for firms 5 years and younger, once for firms 10 years and older ********** 

** young firms
ivreghdfe lelec_int (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if young_firm==1
eststo: round
ivreghdfe lelec_int (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7 & young_firm==1
eststo: round
ivreghdfe lco2_int_i_both (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if young_firm==1
eststo: round
ivreghdfe lbtu_int_i_both (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if young_firm==1
eststo: round

esttab using "/projects/disclosure/20240417/output/robustness_energy_intensity_young_firms_T13T26.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity") title("for young firms only") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear


** old firms
ivreghdfe lelec_int (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if old_firm==1
eststo: round
ivreghdfe lelec_int (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7 & old_firm==1
eststo: round
ivreghdfe lco2_int_i_both (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if old_firm==1
eststo: round
ivreghdfe lbtu_int_i_both (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.ye##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if old_firm==1
eststo: round

esttab using "/projects/disclosure/20240417/output/robustness_energy_intensity_old_firms_T13T26.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity") title("for old firms only") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear

drop old_firm young_firm


********** Run Wald tests for regressions in table A.9 ********** 

*** Metals
preserve 
gen ind = 0
replace ind = 1 if inlist(naicscode3, 331, 332)

gen lelec_price_initXind = lelec_price_init * ind
gen instr_B_cl_initXind  = instr_B_cl_init * ind
gen instr_B_ng_initXind  = instr_B_ng_init * ind
gen instr_B_pa_initXind  = instr_B_pa_init * ind

ivreghdfe lelec_int  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
gen p_value = `r(p)'
gen F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m1 = (`r(mean)')
sum F_stat
mat m1 = (m1, `r(mean)')

ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe we_scale  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe wh  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

mat rownames m1 = log(Electricity_Intensity) log(CO2_Intensity) log(BTU_Intensity) log(Energy_Productivity) log(TFP) 
mat colnames m1 = p-value F-stat

esttab matrix(m1) using "/projects/disclosure/20240417/output/ind_heterogeneity_3digit_wald_T13T26.xls", title(Metals) replace star(* 0.10 ** 0.05 *** 0.01) 
eststo clear 
restore


*** Minerals
preserve 
gen ind = 0
replace ind = 1 if inlist(naicscode3, 324, 327)

gen lelec_price_initXind = lelec_price_init * ind
gen instr_B_cl_initXind  = instr_B_cl_init * ind
gen instr_B_ng_initXind  = instr_B_ng_init * ind
gen instr_B_pa_initXind  = instr_B_pa_init * ind

ivreghdfe lelec_int  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
gen p_value = `r(p)'
gen F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m1 = (`r(mean)')
sum F_stat
mat m1 = (m1, `r(mean)')

ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe we_scale  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe wh  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

mat rownames m1 = log(Electricity_Intensity) log(CO2_Intensity) log(BTU_Intensity) log(Energy_Productivity) log(TFP) 
mat colnames m1 = p-value F-stat

esttab matrix(m1) using "/projects/disclosure/20240417/output/ind_heterogeneity_3digit_wald_T13T26.xls", title(Minerals) append star(* 0.10 ** 0.05 *** 0.01) 
eststo clear 
restore

**# Bookmark #1


*** Chemicals
preserve 
gen ind = 0
replace ind = 1 if inlist(naicscode3, 325, 326)

gen lelec_price_initXind = lelec_price_init * ind
gen instr_B_cl_initXind  = instr_B_cl_init * ind
gen instr_B_ng_initXind  = instr_B_ng_init * ind
gen instr_B_pa_initXind  = instr_B_pa_init * ind

ivreghdfe lelec_int  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
gen p_value = `r(p)'
gen F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m1 = (`r(mean)')
sum F_stat
mat m1 = (m1, `r(mean)')

ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe we_scale  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe wh  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

mat rownames m1 = log(Electricity_Intensity) log(CO2_Intensity) log(BTU_Intensity) log(Energy_Productivity) log(TFP) 
mat colnames m1 = p-value F-stat

esttab matrix(m1) using "/projects/disclosure/20240417/output/ind_heterogeneity_3digit_wald_T13T26.xls", title(Chemicals) append star(* 0.10 ** 0.05 *** 0.01) 
eststo clear 
restore



*** Agricultural Machinery
preserve 
gen ind = 0
replace ind = 1 if inlist(naicscode3, 333)

gen lelec_price_initXind = lelec_price_init * ind
gen instr_B_cl_initXind  = instr_B_cl_init * ind
gen instr_B_ng_initXind  = instr_B_ng_init * ind
gen instr_B_pa_initXind  = instr_B_pa_init * ind

ivreghdfe lelec_int  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
gen p_value = `r(p)'
gen F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m1 = (`r(mean)')
sum F_stat
mat m1 = (m1, `r(mean)')

ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe we_scale  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe wh  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

mat rownames m1 = log(Electricity_Intensity) log(CO2_Intensity) log(BTU_Intensity) log(Energy_Productivity) log(TFP) 
mat colnames m1 = p-value F-stat

esttab matrix(m1) using "/projects/disclosure/20240417/output/ind_heterogeneity_3digit_wald_T13T26.xls", title(Agricultural Machinery) append star(* 0.10 ** 0.05 *** 0.01) 
eststo clear 
restore


*** Electrical Goods
preserve 
gen ind = 0
replace ind = 1 if inlist(naicscode3, 334, 335)

gen lelec_price_initXind = lelec_price_init * ind
gen instr_B_cl_initXind  = instr_B_cl_init * ind
gen instr_B_ng_initXind  = instr_B_ng_init * ind
gen instr_B_pa_initXind  = instr_B_pa_init * ind

ivreghdfe lelec_int  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
gen p_value = `r(p)'
gen F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m1 = (`r(mean)')
sum F_stat
mat m1 = (m1, `r(mean)')

ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe we_scale  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe wh  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

mat rownames m1 = log(Electricity_Intensity) log(CO2_Intensity) log(BTU_Intensity) log(Energy_Productivity) log(TFP) 
mat colnames m1 = p-value F-stat

esttab matrix(m1) using "/projects/disclosure/20240417/output/ind_heterogeneity_3digit_wald_T13T26.xls", title(Electrical Goods) append star(* 0.10 ** 0.05 *** 0.01) 
eststo clear 
restore



*** Transport Goods
preserve 
gen ind = 0
replace ind = 1 if inlist(naicscode3, 336)

gen lelec_price_initXind = lelec_price_init * ind
gen instr_B_cl_initXind  = instr_B_cl_init * ind
gen instr_B_ng_initXind  = instr_B_ng_init * ind
gen instr_B_pa_initXind  = instr_B_pa_init * ind

ivreghdfe lelec_int  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
gen p_value = `r(p)'
gen F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m1 = (`r(mean)')
sum F_stat
mat m1 = (m1, `r(mean)')

ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe we_scale  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe wh  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

mat rownames m1 = log(Electricity_Intensity) log(CO2_Intensity) log(BTU_Intensity) log(Energy_Productivity) log(TFP) 
mat colnames m1 = p-value F-stat

esttab matrix(m1) using "/projects/disclosure/20240417/output/ind_heterogeneity_3digit_wald_T13T26.xls", title(Transport Goods) append star(* 0.10 ** 0.05 *** 0.01) 
eststo clear 
restore



*** Food, Drink, Tobacco
preserve 
gen ind = 0
replace ind = 1 if inlist(naicscode3, 311, 312)

gen lelec_price_initXind = lelec_price_init * ind
gen instr_B_cl_initXind  = instr_B_cl_init * ind
gen instr_B_ng_initXind  = instr_B_ng_init * ind
gen instr_B_pa_initXind  = instr_B_pa_init * ind

ivreghdfe lelec_int  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
gen p_value = `r(p)'
gen F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m1 = (`r(mean)')
sum F_stat
mat m1 = (m1, `r(mean)')

ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe we_scale  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe wh  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

mat rownames m1 = log(Electricity_Intensity) log(CO2_Intensity) log(BTU_Intensity) log(Energy_Productivity) log(TFP) 
mat colnames m1 = p-value F-stat

esttab matrix(m1) using "/projects/disclosure/20240417/output/ind_heterogeneity_3digit_wald_T13T26.xls", title(Food, Drink, Tobacco) append star(* 0.10 ** 0.05 *** 0.01) 
eststo clear 
restore



*** Textile, Leather, Shoes
preserve 
gen ind = 0
replace ind = 1 if inlist(naicscode3, 313, 314, 315, 316)

gen lelec_price_initXind = lelec_price_init * ind
gen instr_B_cl_initXind  = instr_B_cl_init * ind
gen instr_B_ng_initXind  = instr_B_ng_init * ind
gen instr_B_pa_initXind  = instr_B_pa_init * ind

ivreghdfe lelec_int  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
gen p_value = `r(p)'
gen F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m1 = (`r(mean)')
sum F_stat
mat m1 = (m1, `r(mean)')

ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe we_scale  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe wh  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

mat rownames m1 = log(Electricity_Intensity) log(CO2_Intensity) log(BTU_Intensity) log(Energy_Productivity) log(TFP) 
mat colnames m1 = p-value F-stat

esttab matrix(m1) using "/projects/disclosure/20240417/output/ind_heterogeneity_3digit_wald_T13T26.xls", title(Textile, Leather, Shoes) append star(* 0.10 ** 0.05 *** 0.01) 
eststo clear 
restore



*** Timber and Furniture
preserve 
gen ind = 0
replace ind = 1 if inlist(naicscode3, 321)

gen lelec_price_initXind = lelec_price_init * ind
gen instr_B_cl_initXind  = instr_B_cl_init * ind
gen instr_B_ng_initXind  = instr_B_ng_init * ind
gen instr_B_pa_initXind  = instr_B_pa_init * ind

ivreghdfe lelec_int  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
gen p_value = `r(p)'
gen F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m1 = (`r(mean)')
sum F_stat
mat m1 = (m1, `r(mean)')

ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe we_scale  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe wh  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

mat rownames m1 = log(Electricity_Intensity) log(CO2_Intensity) log(BTU_Intensity) log(Energy_Productivity) log(TFP) 
mat colnames m1 = p-value F-stat

esttab matrix(m1) using "/projects/disclosure/20240417/output/ind_heterogeneity_3digit_wald_T13T26.xls", title(Timber and Furniture) append star(* 0.10 ** 0.05 *** 0.01) 
eststo clear 
restore



*** Printing and Paper Products
preserve 
gen ind = 0
replace ind = 1 if inlist(naicscode3, 322, 323)

gen lelec_price_initXind = lelec_price_init * ind
gen instr_B_cl_initXind  = instr_B_cl_init * ind
gen instr_B_ng_initXind  = instr_B_ng_init * ind
gen instr_B_pa_initXind  = instr_B_pa_init * ind

ivreghdfe lelec_int  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
gen p_value = `r(p)'
gen F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m1 = (`r(mean)')
sum F_stat
mat m1 = (m1, `r(mean)')

ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe we_scale  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

ivreghdfe wh  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2

mat rownames m1 = log(Electricity_Intensity) log(CO2_Intensity) log(BTU_Intensity) log(Energy_Productivity) log(TFP) 
mat colnames m1 = p-value F-stat

esttab matrix(m1) using "/projects/disclosure/20240417/output/ind_heterogeneity_3digit_wald_T13T26.xls", title(Printing and Paper Products) append star(* 0.10 ** 0.05 *** 0.01) 
eststo clear 
restore



*** Misc Manufacturing
preserve 
gen ind = 0
replace ind = 1 if inlist(naicscode3, 339)

gen lelec_price_initXind = lelec_price_init * ind
gen instr_B_cl_initXind  = instr_B_cl_init * ind
gen instr_B_ng_initXind  = instr_B_ng_init * ind
gen instr_B_pa_initXind  = instr_B_pa_init * ind

ivreghdfe lelec_int  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
gen p_value = `r(p)'
gen F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m1 = (`r(mean)')
sum F_stat
mat m1 = (m1, `r(mean)')


ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2


ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2


ivreghdfe we_scale  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2


ivreghdfe wh  (lelec_price lelec_price_init lelec_price_initXind = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init instr_B_cl_initXind instr_B_ng_initXind instr_B_pa_initXind) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
test lelec_price_init + lelec_price_initXind = 0
replace p_value = `r(p)'
replace F_stat = `r(F)'
foreach var in "p_value" "F_stat" {
	if "`var'"=="" exit
	replace `var' = sign(`var')*round(abs(`var'),10^(floor(log10(abs(`var')))-3)) if `var'!=0
}
sum p_value
mat m2 = (`r(mean)')
sum F_stat
mat m2 = (m2, `r(mean)')

mat m1 = m1 \ m2


mat rownames m1 = log(Electricity_Intensity) log(CO2_Intensity) log(BTU_Intensity) log(Energy_Productivity) log(TFP) 
mat colnames m1 = p-value F-stat

esttab matrix(m1) using "/projects/disclosure/20240417/output/ind_heterogeneity_3digit_wald_T13T26.xls", title(Misc Manufacturing) append star(* 0.10 ** 0.05 *** 0.01) 
eststo clear 
restore

